package com.kkd.kkdapp.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;

import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.BaseActivity;
import com.kkd.kkdapp.listener.OnSingleClickListener;

/**
 * 转让提交成功页
 */
public class DebtSuccessActivity extends BaseActivity {

	private Context mContext = this;

	private TextView bidname;
	private TextView tenderamount;
	private TextView num_fenshu;
	private TextView price;
	private TextView xishu_debt;
	private TextView yujifuwufei;
	private TextView lasttime;
	private View continue_bt;
	private String bidTitle;
	private String expectAmount;
	private String expectPart;
	private String transPrice;
	private String ratio;
	private String serviceFee;
	private String lastDate;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_debt_success);
		getMessage();
		initView();
		initListener();
		setData();
	}

	private void initView() {
		// 名称
		bidname = (TextView) findViewById(R.id.bidname);
		// 预期收入
		tenderamount = (TextView) findViewById(R.id.tenderamount);
		// 预期转让份数
		num_fenshu = (TextView) findViewById(R.id.num_fenshu);
		// 转让价格
		price = (TextView) findViewById(R.id.price);
		// 转让系数
		xishu_debt = (TextView) findViewById(R.id.xishu_debt);
		// 预计服务费
		yujifuwufei = (TextView) findViewById(R.id.yujifuwufei);
		// 最后转让日
		lasttime = (TextView) findViewById(R.id.lasttime);
		// 完成按钮
		continue_bt = findViewById(R.id.continue_bt);
	}

	private void initListener() {
		continue_bt.setOnClickListener(new OnSingleClickListener() {

			@Override
			public void onSingleClick(View v) {
				Intent intent = new Intent(mContext,
						MyRegularDebtActivity.class);
				intent.putExtra("setItem", true);
				intent.putExtra("curItem", 1);
				startActivity(intent);
				finish();
				try {
					MyRegularDebtActivity.mActivity.finish();
					MyDebtDetailActivity.mActivity.finish();
				} catch (Exception e) {

				}
			}
		});
	}

	private void getMessage() {
		Intent intent = getIntent();
		bidTitle = intent.getStringExtra("bidTitle");
		expectAmount = intent.getStringExtra("expectAmount");
		expectPart = intent.getStringExtra("expectPart");
		transPrice = intent.getStringExtra("transPrice");
		ratio = intent.getStringExtra("ratio");
		serviceFee = intent.getStringExtra("serviceFee");
		lastDate = intent.getStringExtra("lastDate");
	}

	private void setData() {
		bidname.setText(bidTitle);
		tenderamount.setText(expectAmount);
		num_fenshu.setText(expectPart);
		price.setText(transPrice);
		xishu_debt.setText(ratio + "%");
		yujifuwufei.setText(serviceFee + "元(最多)");
		lasttime.setText(lastDate);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent intent = new Intent(mContext, MyRegularDebtActivity.class);
			intent.putExtra("setItem", true);
			intent.putExtra("curItem", 1);
			startActivity(intent);
			finish();
			try {
				MyRegularDebtActivity.mActivity.finish();
				MyDebtDetailActivity.mActivity.finish();
			} catch (Exception e) {

			}
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
}
